package com.riant.day07;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Classname Demo03
 * @Description TODO
 * @Date 2021/3/20 15:19
 * @Created by 张斌
 */
public class Demo03 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        String value = map.put("a", "v");
        System.out.println(value);
        value = map.put("a", "2");
        System.out.println(value);
        map.put("c", "3");
        //1、获取map中Key的集合
        Set<String> set = map.keySet();
        set.forEach(item -> System.out.println(map.get(item)));
        //2、获取map中value的集合
        Collection<String> collection = map.values();
        collection.forEach(item -> System.out.println(item.toString()));
        //3、获取map中映射的集合，买一个Entry代表一个键值对
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        entrySet.forEach(item -> {
                    if ("a".equals(item.getKey())) {
                        item.setValue("a");
                    }
                    System.out.println(item.equals(map));
                    System.out.println("key:" + item.getKey() + ",value:" + item.getValue());
                }
        );
    }
}
